# -*- coding: utf-8 -*-

from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup


def get_title(url):
    try:
        html = urlopen(url)
    except HTTPError as e:
        print(e)
        return None
    
    try:
        bs_obj = BeautifulSoup(html.read(), 'html.parser')
        title = bs_obj.body.h1.text
    except AttributeError as e:
        return None
    
    return title


title = get_title('http://lavenliu.cn/post/test01.html')
if title is None:
    print('Title could not be found')
else:
    print(title)
